package org.example.myerp.controller;

import java.util.List;

import javax.servlet.http.HttpSession;



import org.example.myerp.pojo.*;
import org.example.myerp.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

//@CrossOrigin(methods = { RequestMethod.POST, RequestMethod.GET }, allowCredentials = "true", allowedHeaders = "*")

@RestController
@RequestMapping("/system/menu")
public class MenuController {
	@Autowired
    MenuService menuService;






	@RequestMapping("/getMenus")
	public PageMyself<Menu> findByPager(Integer pageNum, Integer pageSize) {
		PageMyself<Menu> findByPager = menuService.findByPager(pageNum, pageSize);
		return findByPager;
	}

	@RequestMapping("/oneMenus")
	public List<Menu> oneLevelIdName() {
		return menuService.oneLevelIdName();
	}

	@RequestMapping("/addMenu")
	public Integer addMenu(Menu menu) {
		if (menu.getP_mid()==null||!menu.getP_mid().equals("")) {
			menu.setP_mid(0);
		}
		return menuService.addMenu(menu);
	}
	@RequestMapping("/delMenus")
	public void delMenus(Integer mid) {
		menuService.delMenus(mid);
	}
	@RequestMapping("/batchDelMenus")
	public void batchDdelMenus(int[] mids) {
		menuService.batchDdelMenus(mids);
	}
	@RequestMapping("/updateMenu")
	public void updateMenu(Menu menu) {
		menuService.updateMenu(menu);
	}

	@RequestMapping("/loadMainMenu")
	public List<LoadMenus> loadMainMenu(HttpSession session) {
		User user = (User)session.getAttribute("user");
		return menuService.loadMainMenu(Integer.valueOf(user.getUid()));
	}

	@RequestMapping("/roleTree")
	public WebRoleTree roleTree(Integer rid) {
		return menuService.roleTree(rid);
	}


	@RequestMapping("/get")
	public List<Tree> getmenus() {
		return menuService.getMenus();

	}
}
